/**
 * [后台菜单管理]列表首页[JS]
 * @returns {*}
 */
var app = function () {
    Vue.component('treeselect', VueTreeselect.Treeselect);
    return new Vue({
        el: '#vueContainer',
        data: {
            loadOver: false,
            detailOver: false,
            setting: {
                pageType: 'index',      // 页面类型
                showAllSearch: false,   // 展示全部查询
                dialogVis: false,
                clearVis: false,        // 清除缓存弹出层
                isAdd: false,           // 是否添加数据
                treeRightHover: false,  // 数级菜单是否移入
                showClearConfirm: true, // 是否展示信息清除缓存改变弹出层
                bodyWidth: document.documentElement.clientWidth, // body宽度
            },
            baseDiaTitle: '',     // 弹出层基础标题
            dataList: [],         // 父级数据列表
            addDataList: [],      // 添加修改数据
            handleSelectList: [], // 当前多选项
            showTopScroll: false, // 是否已滚动，默认否
            page: 1,
            page_size: 20,
            dataTotal: 0,
            addForm: {},
            searchForm: {
                group: [ // 组合查询
                    {name: 'name', text: '标题'},
                ],
                groupOther: [
                    {name: 'status', type: 'radio', text: '状态'},
                ],         // 组合查询 右侧
                base: [

                ],         // 基础
                more: [],  // 更多
                value: {}  // 值
            },                // 查询表单数据
            filterText: '',
            customErrMsg: {}, // 自定义错误信息,
            clearCache: {
                showClearDialog: false, // 清除缓存弹出层
                showClearLoading: false, // 清除缓存弹出层正在加载
                pageUrl: '', // 清除缓存连接
            }, // 清除缓存内容
            pageDialog: {
                show: false,    // 页面 - 是否展示弹出层
                url: '',        // 页面 - 弹出层连接
                loading: false, // 页面 - 弹出层加载中
                isIframe: false // 页面 - 是否[iframe]嵌入
            },
        },
        created: function () {
            // 初始化
            this.init();
            // 初始化设置
            this.getSetting();
            var that = this;
            this.$nextTick(function () {
                that.loadOver = true;
                that.initMainScroll();
            });
        },
        methods: {
            /**
             * 初始化的逻辑
             */
            init: function () {

                var params = $w.getParams();
                // 是否[iframe]嵌入
                this.pageDialog.isIframe = window.self !== window.top;

                var that = this;
                // [嵌入]返回事件监听 直接走自己的返回
                if (this.pageDialog.isIframe) {
                    window.addEventListener("popstate", function($event) {
                        if (that.cancel) that.cancel(); // 返回上一页
                        window.history.forward(-1);     // 清理此页历史记录
                    }, false);
                    window.history.pushState({
                        title: "title", url: "#"
                    }, "title", "#");
                    window.history.forward(1);
                }

                this.$nextTick(function () {
                    // 监听主滚动条
                    that.$refs['mainScroller'].wrap.addEventListener('scroll', function ($event) {
                        that.showTopScroll = $event.srcElement.scrollTop > 10; // 顶部以滚动
                    })
                });
            },
            /**
             * 初始化滚动条
             */
            initMainScroll: function () {
                var shadowDom = this.$refs['mainScrollShadow'];
                if (!shadowDom) return false;
                this.$refs.mainScroller.wrap.onscroll = function ($event) {
                    var opacity = 0;
                    opacity = $event['srcElement']['scrollTop'] / 100;
                    opacity = opacity > 0.6 ? 0.6 : opacity
                    shadowDom['$el']['style']['box-shadow'] = '0 5px 15px 0 rgb(204, 204, 204, ' + opacity + ')';
                };
            },
            /**
             * 初始化添加、修改[表单]
             */
            initAddForm: function () {
                this.addForm = {
                    name: null,
                    parent_id: null,
                    sort: 100,
                    status: 1,
                    url: null,
                    font_icon: null
                };
            },
            /**
             * 顶部查询 - 初始化查询[FORM]
             * @param $isClear
             * @returns {boolean}
             */
            initSearchForm: function ($isClear) {

                // 暂存
                var stage;
                // 赋值默认值
                for (var i in this.setting) {
                    if (!this.setting.hasOwnProperty(i)) continue;
                    // 不存在指定字符串直接返回
                    if (i.indexOf('default_') === -1 && i.indexOf('_list') === -1) continue;

                    // 字段是列表值 需要更改键
                    if (i.indexOf('_list') !== -1) {
                        this.setting[i] = $w.array_index(this.setting[i], 'key');
                    }

                    // 组合字段右侧 默认值, 值列表
                    for (var x in this.searchForm['groupOther']) {
                        if (!this.searchForm['groupOther'].hasOwnProperty(x)) continue;
                        if (!this.searchForm['groupOther'][x]) continue;
                        // 字段默认值 键值
                        stage = 'default_' + this.searchForm['groupOther'][x]['name'];
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['groupOther'][x], 'default',
                                this.setting[i]
                            );
                            continue;
                        }

                        // 字段默列表 键值
                        stage = this.searchForm['groupOther'][x]['name'] + '_list';
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['groupOther'][x], 'option',
                                this.setting[i]
                            );
                        }
                    }

                    // 基础字段 默认值, 值列表
                    for (var y in this.searchForm['base']) {
                        if (!this.searchForm['base'].hasOwnProperty(y)) continue;
                        if (!this.searchForm['base'][y]) continue;
                        // 字段默认值 键值
                        stage = 'default_' + this.searchForm['base'][y]['name'];
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['base'][y], 'default',
                                this.setting[i]
                            );
                            continue;
                        }

                        // 字段默列表 键值
                        stage = this.searchForm['base'][y]['name'] + '_list';
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['base'][y], 'option',
                                this.setting[i]
                            );
                        }
                    }

                    // 更多字段 默认值, 值列表
                    for (var z in this.searchForm['more']) {
                        if (!this.searchForm['more'].hasOwnProperty(z)) continue;
                        if (!this.searchForm['more'][z]) continue;
                        // 字段默认值 键值
                        stage = 'default_' + this.searchForm['more'][z]['name'];
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['more'][z], 'default',
                                this.setting[i]
                            );
                            continue;
                        }

                        // 字段默列表 键值
                        stage = this.searchForm['more'][z]['name'] + '_list';
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['more'][z], 'option',
                                this.setting[i]
                            );
                        }
                    }
                }
            },
            /**
             * 获取设置
             * @returns {boolean}
             */
            getSetting: function () {
                // 正在加载...
                var loadingInstance = ELEMENT.Loading.service({
                    fullscreen: false,
                    text: '加载中...'
                });
                var that = this;

                // 获取各模块的值
                $w.request({
                    url: $w.getApiUrl('adminMenu.setting'),
                    type: 'get',
                    data: {
                        type: 'index' // 首页
                    },
                    dataType: 'json',
                    afterCallback: function () {
                        that.$nextTick(function () {
                            // 获取下列表
                            that.getList(false);
                            // 隐藏正在加载
                            loadingInstance.close();
                        });
                    },
                    callback: function (event) {

                        // 失败的返回|提示
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: event.msg ? event.msg : '操作失败，请稍后尝试'
                            });
                        }

                        // 挨个赋值[setting]中
                        for (var i in event.data) {
                            if (!event.data.hasOwnProperty(i)) continue;
                            that.$set(that.setting, i, event.data[i]);

                            // 字段是列表值 需要更改键
                            if (i.indexOf('_list') !== -1) {
                                that.setting[i] = $w.array_index(that.setting[i], 'key');
                            }
                        }

                        // 清空性初始化基础查询
                        that.initSearchForm(true);

                        // 监测屏幕大小变化
                        return $(window).resize(function () {
                            // 超过此宽度展示 更多筛选
                            var bodyDom = document.getElementsByTagName('body');
                            if (bodyDom[0] &&
                                bodyDom[0].clientWidth <= that.setting.smallScreenWidth
                            ) {
                                return that.setting.isSmallScreen = true;
                            }
                            return that.setting.isSmallScreen = false;
                        });
                    }
                });
            },
            /**
             * 获取下列表
             */
            getList: function ($noLoading) {

                $noLoading = $noLoading === true;

                // 正在加载...
                if (!$noLoading) var loadingInstance = ELEMENT.Loading.service({
                    fullscreen: false,
                    text: '加载中...'
                });
                var that = this;

                // 获取各模块的值
                $w.request({
                    url: $w.getApiUrl('adminMenu.list'),
                    type: 'get',
                    data: {
                        page: this.page,
                        page_size: this.page_size,
                        search: this.searchForm.value
                    },
                    dataType: "json",
                    afterCallback: function () {
                        that.$nextTick(function () {
                            // 隐藏正在加载
                            if (!$noLoading) loadingInstance.close();
                        });
                    },
                    callback: function (event) {

                        // 失败的返回|提示
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: event.msg ? event.msg : '操作失败，请稍后尝试'
                            });
                        }

                        // 数据
                        that.dataList = event.data.list;

                        // 总条目
                        that.dataTotal = parseInt(event.data.total);
                        // 复制下添加数据列表
                        that.addDataList = [
                            {
                                id: 0,
                                label: '作为顶部菜单',
                                parent_id: false
                            }
                        ];
                        Array.prototype.push.apply(that.addDataList, that.dataList);
                        that.$nextTick(function () {

                            // 调用下查找
                            that.$refs.tree.filter(that.searchForm.label);
                            // 隐藏正在加载
                            if (!$noLoading) loadingInstance.close();
                        });
                    }
                });
            },
            /**
             * 恢复记录
             */
            openItem: function ($id) {

                // 如果 $id 不传值 就 走列表
                if (!$id || $id.length <= 0) {
                    $id = this.handleSelectList;
                }

                // 判断id是否为空
                if (!$id || $id.length <= 0) {
                    return this.$message({
                        showClose: true,
                        type: 'error',
                        message: '请至少选择一个条目'
                    });
                }

                var that = this;

                this.$confirm('此操作将【开启】数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '正在开启...'
                    });

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminMenu.open'),
                        type: 'POST',
                        data: {idList: $id},
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 放空列表
                            that.handleSelectList = null;
                            // 成功 加载下列表
                            return that.$nextTick(function () {

                                that.getList(false);
                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        }
                    });
                });
            },
            /**
             * 禁用记录
             */
            disabledItem: function ($id) {

                // 如果 $id 不传值 就 走列表
                if (!$id || $id.length <= 0) {
                    $id = this.handleSelectList;
                }

                // 判断id是否为空
                if (!$id || $id.length <= 0) {
                    return this.$message({
                        showClose: true,
                        type: 'error',
                        message: '请至少选择一个条目'
                    });
                }

                var that = this;

                this.$confirm('此操作将【禁用】数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '禁用中...'
                    });

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminMenu.disabled'),
                        type: 'POST',
                        data: {idList: $id},
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 放空列表
                            that.handleSelectList = null;
                            // 成功 加载下列表
                            return that.$nextTick(function () {

                                that.getList(false);
                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        }
                    });
                });
            },
            /**
             * 排序
             * @param $sortData
             * @returns {*}
             */
            sortItem: function ($sortData) {

                if (!$sortData || $sortData.length < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '暂无子集，无法排序'
                    });
                }

                var loadingInstance = ELEMENT.Loading.service({
                    fullscreen: false,
                    text: '提交中...'
                });
                var that = this;
                $w.request({
                    url: $w.getApiUrl('adminMenu.sort'),
                    type: 'POST',
                    data: {sortData: $sortData},
                    dataType: "json",
                    afterCallback: function () {
                        that.$nextTick(function () {
                            // 隐藏正在加载
                            loadingInstance.close();
                        });
                    },
                    callback: function (event) {

                        // 失败的返回|提示
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: event.msg ? event.msg : '操作失败，请稍后尝试'
                            });
                        }

                        // 提示是否调用刷新缓存
                        return true;
                    }
                });
            },
            /**
             * 提交添加
             */
            submitAdd: function () {

                var that = this;

                // 清空错误信息
                this.$set(that, 'customErrMsg', {});
                this.$refs['addForm'].validate(function (valid, msg) {

                    // 验证不过
                    if (!valid) return false;

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '添加中...'
                    });

                    // 是否越出范围值 大于
                    if (parseInt(that.addForm.sort) > that.setting.sort_max) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最大不得超过 ' + that.setting.sort_max
                        });

                        return loadingInstance.close();
                    }

                    // 是否越出范围值 小于
                    if (parseInt(that.addForm.sort) < that.setting.sort_min) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最小不得小于 ' + that.setting.sort_min
                        });

                        return loadingInstance.close();
                    }

                    $w.request({
                        url: $w.getApiUrl('adminMenu.create'),
                        type: 'POST',
                        data: that.addForm,
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                for (var i in event.data.columnError) {
                                    if (!event.data.columnError.hasOwnProperty(i)) continue;
                                    that.$set(that.customErrMsg, i, event.data.columnError[i]);
                                }
                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            that.setting.dialogVis = false;
                            return that.$nextTick(function () {
                                that.getList(false);
                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        }
                    });
                });
            },
            /**
             * 提交修改
             * @param $ref
             * @returns {boolean}
             */
            submitUpdate: function ($ref) {

                if (!$w.in_array($ref, ['addForm', 'stageForm'])) {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: '更新失败'
                    });
                    console.error('更新方法参数`$ref`非法：' + $ref);
                    return false;
                }
                var that = this;

                // 清空错误信息
                this.$set(that, 'customErrMsg', {});
                this.$refs[$ref].validate(function (valid, msg) {

                    // 验证不过
                    if (!valid) return false;

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '更新中...',
                        customClass: 'z-index-top'
                    });

                    // 是否越出范围值 大于
                    if (parseInt(that.addForm.sort) > that.setting.sort_max) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最大不得超过 ' + that.setting.sort_max
                        });

                        return loadingInstance.close();
                    }

                    // 是否越出范围值 小于
                    if (parseInt(that.addForm.sort) < that.setting.sort_min) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最小不得小于 ' + that.setting.sort_min
                        });

                        return loadingInstance.close();
                    }

                    $w.request({
                        url: $w.getApiUrl('adminMenu.update'),
                        type: 'POST',
                        data: that.addForm,
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                for (var i in event.data.columnError) {
                                    if (!event.data.columnError.hasOwnProperty(i)) continue;
                                    that.$set(that.customErrMsg, i, event.data.columnError[i]);
                                }
                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            that.setting.dialogVis = false;
                            return that.$nextTick(function () {
                                that.getList(true);
                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        }
                    });
                });
            },
            /**
             * 过滤是否展示节点
             */
            filterNode: function ($value, $data) {
                if (!$value) return true;
                return $data.label.indexOf($value) !== -1;
            },
            /**
             * 跳转到添加
             */
            goToCreate: function ($id, $node) {

                // 检测级别
                if ($node && parseInt($node['level']) === 3) {

                    return this.$message({
                        showClose: true,
                        type: 'warning',
                        message: '三级菜单下无法再添加子集：因为无法展示。'
                    });
                }

                // 先初始化添加表单
                this.initAddForm();
                // [$id]存在，赋值
                if ($id && $id.length > 0) this.addForm.parent_id = $id;
                // 操作弹出框标题
                this.baseDiaTitle = '添加';
                // 表示正在添加
                this.setting.isAdd = true;
                // 展示弹出
                this.setting.dialogVis = true;
                // 详情加载完毕
                this.detailOver = true;
                // 获取列表
                this.getList(true);
            },
            /**
             * 跳转到编辑
             */
            goToUpdate: function ($id) {

                // 判断id是否为空
                if (!$id || $id.length <= 0) {
                    return this.$message({
                        showClose: true,
                        type: 'error',
                        message: '请至少选择一个条目'
                    });
                }

                var that = this;
                // 详情加载中
                this.detailOver = false;

                // 正在加载。。
                var loadingInstance = ELEMENT.Loading.service([]);

                // 获取各模块的值
                $w.request({
                    url: $w.getApiUrl('adminMenu.detail'),
                    type: 'GET',
                    data: {id: $id},
                    dataType: "json",
                    afterCallback: function () {
                        that.$nextTick(function () {
                            // 隐藏正在加载
                            loadingInstance.close();
                            // 详情加载完毕
                            that.detailOver = true;
                        });
                    },
                    callback: function (event) {

                        // 失败的返回|提示
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: event.msg ? event.msg : '操作失败，请稍后尝试'
                            });
                        }


                        // 放空列表
                        that.addForm = event.data;
                        // 成功 加载下列表
                        return that.$nextTick(function () {

                            this.baseDiaTitle = '修改';
                            this.setting.isAdd = false;
                            this.setting.dialogVis = true;
                        });
                    }
                });
            },
            /**
             * 检测树菜单点选
             * @param $data
             * @param $checked
             * @param $indeterminate
             */
            handleTreeCheck: function ($data, $checked, $indeterminate) {

                // 初始化下
                if (!this.handleSelectList || this.handleSelectList.length < 1) {
                    this.handleSelectList = [];
                }

                // 选中
                if ($checked) {
                    this.handleSelectList.push($data['id']);
                } else {
                    var item;
                    for (var i in this.handleSelectList) {
                        if (!this.handleSelectList.hasOwnProperty(i)) continue;
                        item = this.handleSelectList[i];
                        if (item['id'] === $data['id']) {
                            delete this.handleSelectList[i];
                        }
                    }
                }
            },
            /**
             * 监测拖拽完成
             */
            handleNodeDrop: function ($draggingNode, $dropNode, $dropType, $ev) {

                // 默认先赋值移动的数据
                this.addForm = $draggingNode['data'];

                // 加入到某节点之前
                if ($dropType === 'before') {

                    // 当前[父级编号] 为被捉拽对象的父级编号
                    this.addForm['parent_id'] = $dropNode['data']['parent_id'];
                    // 排序大于当节点排序
                    this.addForm['sort'] = parseInt($dropNode['data']['sort']) + 1;
                } else if ($dropType === 'after') { // 之后

                    // 当前[父级编号] 为被捉拽对象的父级编号
                    this.addForm['parent_id'] = $dropNode['data']['parent_id'];
                    // 排序小于当节点排序
                    this.addForm['sort'] = parseInt($dropNode['data']['sort']) - 1;
                } else if ($dropType === 'inner') { // 加入到某节点之下

                    // 当前[父级编号] 为被捉拽对象的父级编号
                    this.addForm['parent_id'] = $dropNode['data']['id'];
                    // 循环格式化排序
                    var sort = 1;
                    var children = $dropNode['data']['children'];
                    for (var i in children) {
                        if (!children.hasOwnProperty(i)) continue;

                        // 判断编号如果和正在 更新的一样
                        if (parseInt(children[i]['sort']) < sort) {
                            // 排序值赋值
                            sort = children[i]['sort'];
                        }
                    }
                    // 排序小于当节点排序
                    this.addForm['sort'] = parseInt(sort) - 1;
                }

                // 执行下更新
                this.submitUpdate('stageForm');
            },
            /**
             * 实时监测菜单是否可放置
             * @param $draggingNode
             * @param $dropNode
             * @param $dropType
             * @returns {boolean}
             */
            treeAllowDrop: function ($draggingNode, $dropNode, $dropType) {

                // 加入到某节点之前
                if ($dropType === 'prev' && $dropNode.level > 3) {

                    return false
                } else if ($dropType === 'next' && $dropNode.level > 3) { // 之后

                    return false;
                } else if ($dropType === 'inner' && $dropNode.level >= 3) { // 加入到某节点之下

                    return false;
                }
                return true;
            },
            /**
             * 提交渲染菜单
             */
            renderMenu: function () {

                var that = this;

                this.$confirm('确定要渲染菜单吗, 渲染后后台将展示最新菜单, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '渲染中...'
                    });

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminMenu.render'),
                        type: 'POST',
                        data: {},
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 成功 加载下列表
                            return true;
                        }
                    });
                });
            },
            /**
             * 清除缓存 - 展示清除角色缓存弹出层
             */
            showClearDialog: function () {

                // 取出[ref]对象
                var cacheCache = this.$refs['clearCache'];
                cacheCache.showDialog = true;
            },
            /**
             * 监测 当列表数据改变
             */
            dataChange: function () {
                // 提示被关闭不提示
                if (!this.setting.showClearConfirm) {
                    return false;
                }
                var that = this;
                // 提示是否调用刷新缓存
                this.$confirm('您已改变菜单数据刷新缓存后才会生效，是否选择角色刷新？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '本次操作不再提示',
                    type: 'warning',
                    dangerouslyUseHTMLString: true,
                    distinguishCancelAndClose: true
                }).then(function () {
                    that.showClearDialog(true);
                }).catch(function ($action) {
                    if ($action === 'cancel') {
                        that.setting.showClearConfirm = false;
                    }
                });
            }
        },
        watch: {
            /**
             * 监测文本过滤
             * @param $val
             */
            'searchForm.label': function ($val) {
                this.$refs.tree.filter($val);
            }
        },
        computed: {
            /**
             * [FORM]规则
             * @returns {*}
             */
            addFormRules: function () {
                if (!this.detailOver) return {};
                return {
                    name: [
                        {required: true, message: '请填写名称', trigger: 'blur'}
                    ],
                    parent_id: [
                        {required: true, message: '请选择上级分类', trigger: 'blur'}
                    ],
                    status: [
                        {required: true, message: '请选择状态', trigger: 'blur'}
                    ],
                    url: [
                        {required: true, message: '请填写菜单连接', trigger: 'blur'}
                    ],
                };
            },
            /**
             * 获得顶部样式
             */
            getTopClass: function () {
                var className = [];
                // 如果已经滚动
                if (this.showTopScroll) className.push('is-scroll');

                return className.join(' ');
            }
        }
    });
};
